package com.jsz.peini.server.thread;

import java.util.List;

import org.apache.log4j.Logger;

import com.jsz.peini.bean.order.OrderInfo;
import com.jsz.peini.bean.user.AccountCode;
import com.jsz.peini.bean.user.UserInfo;
import com.jsz.peini.common.util.PeiniUtils;
import com.jsz.peini.common.util.SpringContextUtil;
import com.jsz.peini.mapper.user.AccountCodeMapper;
import com.jsz.peini.redis.base.RedisConstants;
import com.jsz.peini.redis.base.RedisUtil;
import com.jsz.peini.redis.base.SerializeUtil;
import com.jsz.peini.service.user.UserInfoService;


public class UserRegThread extends Thread{
	
	Logger logger = Logger.getLogger(UserRegThread.class);
	
	private UserInfoService userInfoService;
	
	private AccountCodeMapper accountCodeMapper;
	
	public void init(){
		this.start();
	}
	
	@Override
	public void run() {
		super.run();
		
		userInfoService = (UserInfoService)SpringContextUtil.getBean(UserInfoService.class);
		
		accountCodeMapper = (AccountCodeMapper)SpringContextUtil.getBean(AccountCodeMapper.class);
		
		while(true)
		{
			try {
				//UserInfo userInfo = PeiniUtils.regUserInfos.take();
				List<byte[]> list = RedisUtil.brpop(RedisConstants.USER_REG.getBytes());
				if(list.size() > 1){
					byte [] user = list.get(1);
					UserInfo userInfo = (UserInfo)SerializeUtil.unserialize(user);
					
					userInfoService.allotAccCode(userInfo);
				}
						
				Thread.sleep(1);
			} catch (Exception e1) {
				e1.printStackTrace();
				logger.info("fail", e1);
			}
		}
		
	}
	
}